
import java.util.ArrayList;
import java.util.Random;
	
public class PrimaryUsr {
	
		
		private int ID;	// user ID
		private static int sn = 0; // use sn to generate ID
		public static ArrayList<PrimaryUsr> primary_users; // primary users' list
		
		//0:very low, 1:low,  3: normal  4: severe, 5: almost fully
		private final static int busy_level_range = 5;
		private int busy_level = RandomValue.getRandomValue(busy_level_range);
		
		private ArrayList<Integer> records;	// 0 or 1 for each time slot
		private int x;
		private int y;
		private final int mobile = 0;
		private final int no_of_channel;
		
		public PrimaryUsr() 
		{
			// randomly choose the channel accessed
			this.no_of_channel = RandomValue.getRandomValue(Enviroment.get_Channels_num());
			
			if( primary_users == null)
			{
				primary_users = new ArrayList<PrimaryUsr>();
			}
			
			// get sn of this primary user
			this.ID = sn;
			sn++;
			
			
			//	get the position of itself
			this.x = RandomValue.getRandomValue(Enviroment.get_max_x_range());
			this.y = RandomValue.getRandomValue(Enviroment.get_max_y_range());
			 
			//insert itself to the primary users list
			primary_users.add(this);
		}
		
		
		public static int getSN()
		{
			return PrimaryUsr.sn;
		}
		
		/*
		 * Return the busy level
		 */
		public int getBusyLevel()
		{
			return this.busy_level;
		}
		
		/*
		 * 
		 */
		public void decide_Occupied()
		{
			double deviation = 50;
			double average = 60;
			
			average += ( this.busy_level * 2 );
			Random random = new Random();
			//System.out.println(random.nextInt());
			int val = (int) Math.round(random.nextGaussian() * deviation + average);
			//System.out.println(val);
			if ( val < 50 )
			{
				this.records.add(0);
			}
			else
			{
				this.records.add(1);
			}
		}
		
		public int getOccupiedInformation(int index)
		{
			if(index < this.records.size())
			{
				return this.records.get(index);
			}
			return -1;
		}
		
		public ArrayList<Integer> getRecords()
		{	
			ArrayList<Integer> records_copy = new ArrayList<Integer>();
			
			for(int i = 0; i < this.records.size(); i++)
			{
				records_copy.add(this.records.get(i));
			}
			
			return records_copy;
		}
		
		public int getID()
		{
			return this.ID;
		}
		
		
		public int get_channel_accessed()
		{
			return this.no_of_channel;
		}
		
		public int get_x_axis()
		{
			return this.x;
		}
		
		public int get_y_axis()
		{
			return this.y;
		}
	}
